﻿using DeskRedis.Model;
using System.Windows;
using System.Windows.Controls;

namespace DeskRedis.MyControl.CustomControl
{
    public class ListBoxItem4RedisKey : ListViewItem
    {
        static ListBoxItem4RedisKey()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ListBoxItem4RedisKey),
                new FrameworkPropertyMetadata(typeof(ListBoxItem4RedisKey)));
        }

        #region 本地组件
        private Button btnRefresh;
        private Button btnDelete;
        #endregion


        #region 路由事件
        /// <summary>
        /// 当点击“刷新”按钮时发生。
        /// </summary>
        public event RoutedEventHandler OnRefresh;
        /// <summary>
        /// 当点击“删除”按钮时发生。
        /// </summary>
        public event RoutedEventHandler OnDelete;
        #endregion


        #region 公共属性
        /// <summary>
        /// 节点信息。
        /// </summary>
        public NodeInfo NodeInfo { get; set; }
        #endregion


        #region 重写方法
        public override void BeginInit()
        {
            base.BeginInit();
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.btnRefresh = this.GetTemplateChild("btnRefresh") as Button;
            this.btnDelete = this.GetTemplateChild("btnDelete") as Button;

            this.btnRefresh.Click += (s, e) => { this.OnRefresh?.Invoke(s, new RoutedEventArgs(e.RoutedEvent, this.NodeInfo)); };
            this.btnRefresh.MouseDoubleClick += (s, e) => { return; };
            this.btnDelete.Click += (s, e) => { this.OnDelete?.Invoke(s, new RoutedEventArgs(e.RoutedEvent, this.NodeInfo)); };
            this.btnDelete.MouseDoubleClick += (s, e) => { return; };
        }
        #endregion
    }
}
